home *** CD-ROM | disk | FTP | other *** search
/ PC Graphics Unleashed / PC Graphics Unleashed.iso / ch01 / et4000.asm < prev    next >
Assembly Source File  |  1993-07-31  |  15KB  |  505 lines

  1. ;--------------------------------------------------------------------------
  2. ; This is file ET4000.ASM
  3. ;
  4. ; Copyright (C) 1991 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  5. ; Copyright (C) 1992 Csaba Biegl, 820 Stirrup Dr, Nashville, TN 37221
  6. ;
  7. ; This file is distributed under the terms listed in the document
  8. ; "copying.dj", available from DJ Delorie at the address above.
  9. ; A copy of "copying.dj" should accompany this file; if not, a copy
  10. ; should be available from where this file was obtained.  This file
  11. ; may not be distributed without a verbatim copy of "copying.dj".
  12. ;
  13. ; This file is distributed WITHOUT ANY WARRANTY; without even the implied
  14. ; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. ;--------------------------------------------------------------------------
  16.  
  17. include grdriver.inc
  18. cseg    segment byte public 'code'
  19.     assume  cs:cseg, ds:cseg, es:cseg, ss:nothing
  20.  
  21.  
  22. ;--------------------------------------------------------------------------
  23. ; DRIVER HEADER
  24. ;  The following entries MUST match the structure and constant
  25. ;  declarations in the file 'grdriver.h' of the GRX graphics library
  26. ;  The mode word should contain the following bitfields:
  27. ;     - the GRD_NEW_DRIVER bit set for any new format driver
  28. ;     - the adapter type field should be specified
  29. ;     - the memory size field should be specified
  30. ;     - the paging mode field should be specified
  31. ;  The mode set routine will OR in the plane bitfield as it will
  32. ;  change when different color number modes are requested.
  33. ;--------------------------------------------------------------------------
  34.  
  35.     dw    offset mode_set_routine
  36.     dw    offset paging_routine
  37. mode_W  dw    GRD_NEW_DRIVER+GRD_VGA+GRD_1024K+GRD_RW_64K
  38. ;
  39. ; The 'def_xx' fields are filled in by go32 from the corresponding
  40. ; fields of the 'GO32' environment variable
  41. ;
  42. def_tw  dw    80         ; text width
  43. def_th  dw    25         ; text height
  44. def_gw  dw    640        ; graphics width
  45. def_gh  dw    480        ; graphics height
  46. def_nc  dw    256        ; graphics colors
  47.     dw    offset driver_init_routine
  48.     dw    offset text_mode_table
  49.     dw    offset graphics_mode_table
  50.  
  51. ;
  52. ; Biggest text and graphics sizes
  53. ;
  54. Max_TW  equ    132
  55. Max_TH  equ    50
  56. Max_GWn equ    800        ; non interlaced!!!
  57. Max_GHn equ    600
  58. Max_GW  equ    1024        ; may be interlaced
  59. Max_GH  equ    768
  60.  
  61.  
  62. ;--------------------------------------------------------------------------
  63. ; TABLE OF SUPPORTED TEXT MODES
  64. ;    - keep sorted by size
  65. ;    - end with an all 0 entry
  66. ;    - BIOS field = 0xff disables it
  67. ;    - fields:
  68. ;        width,  height, colors, BIOS#+  setup_procedure_index*256
  69. ;--------------------------------------------------------------------------
  70. text_mode_table           label word
  71.     dw    80,    25,    2,    007h +  00000h
  72.     dw    40,    25,    16,    001h +  00000h
  73.     dw    80,    25,    16,    003h +  00000h
  74.     dw    80,    50,    16,    003h +  00100h
  75.     dw    80,    60,    16,    026h +  00000h
  76.     dw    100,    40,    16,    02ah +  00000h
  77.     dw    132,    25,    16,    023h +  00000h
  78.     dw    132,    28,    16,    024h +  00000h
  79.     dw    132,    44,    16,    022h +  00000h
  80. ;    dw    132,    50,    16,    061h +  00000h
  81.     dw    132,    60,    16,    021h +  00000h
  82.     dw    0,    0,    0,    000h +  00000h
  83.  
  84.  
  85. ;--------------------------------------------------------------------------
  86. ; TABLE OF SUPPORTED GRAPHICS MODES
  87. ;    - keep sorted first by colors then by size
  88. ;    - end with an all 0 entry
  89. ;    - BIOS field = 0xff disables it
  90. ;    - fields:
  91. ;        width,  height, colors, BIOS#+  setup_procedure_index*256
  92. ;--------------------------------------------------------------------------
  93. graphics_mode_table    label word
  94.     dw    320,    200,    16,    00dh +  00000h
  95.     dw    640,    200,    16,    00eh +  00000h
  96.     dw    640,    350,    16,    010h +  00000h
  97.     dw    640,    480,    16,    012h +  00000h
  98.     dw    800,    600,    16,    029h +  00000h
  99.     dw    1024,    768,    16,    037h +  00000h
  100.     dw    320,    200,    256,    013h +  00000h
  101.     dw    640,    350,    256,    02dh +  00000h
  102.         dw    640,    400,    256,    02fh +  00000h
  103.     dw    640,    480,    256,    02eh +  00000h
  104.     dw    800,    600,    256,    030h +  00000h
  105.     dw    1024,    768,    256,    038h +  00000h
  106. ET4000_HiColor_Table    label word
  107.     dw    320,    200,    32768,  013h +  00200h  ; 15 bits
  108.     dw    640,    350,    32768,  02dh +  00200h  ; 15 bits
  109.         dw    640,    400,    32768,  02fh +  00200h  ; 15 bits
  110.     dw    640,    480,    32768,  02eh +  00200h  ; 15 bits
  111.     dw    800,    600,    32768,  030h +  00200h  ; 15 bits
  112.  
  113.     dw    320,    200,    0c010h, 013h +  00300h  ; 16 bits
  114.         dw    640,    350,    0c010h, 02dh +  00300h  ; 16 bits
  115.         dw    640,    400,    0c010h, 02fh +  00300h  ; 16 bits
  116.         dw    640,    480,    0c010h, 02eh +  00300h  ; 16 bits
  117.     dw    800,    600,    0c010h, 030h +  00300h  ; 16 bits
  118.  
  119. ;    dw    320,    200,    0c018h, 013h +  00400h    ; 24 bits
  120.         dw    640,    350,    0c018h, 02dh +  00400h  ; 24 bits
  121.         dw    640,    400,    0c018h, 02fh +  00400h  ; 24 bits
  122.         dw    640,    480,    0c018h, 02eh +  00400h  ; 24 bits
  123.  
  124. ET4000_HiColor_EndTable label word
  125.     dw    0,     0,      0,        000h +  00000h
  126.  
  127.  
  128. ;--------------------------------------------------------------------------
  129. ; TABLE OF SPECIAL SETUP PROCEDURES
  130. ;  You may need such procedures for:
  131. ;     -- reloading fonts on standard EGA or VGA for
  132. ;     higher resolution text modes
  133. ;     -- enable HiColor mode of some Super VGAs
  134. ;     -- Handle the parameter passing conventions of the VESA BIOS
  135. ;     -- put VGA into 256 color plane mode ("MODE X")
  136. ;     -- etc...
  137. ;  There should be one entry in the table for every non-zero
  138. ;  'setup_procedure_index' in the text and graphics mode tables.
  139. ;  The first entry in the table belongs to index 100h, and so on.
  140. ;  The special setup procedure is invoked via a near call.
  141. ;
  142. ;  Entry: DI=address of the mode record from the text or graphics
  143. ;      table to set up.
  144. ;
  145. ;  Exit:  Adapter configured
  146. ;      BX=driver mode word as it should be returned by the mode set
  147. ;         routine. Typically it involves picking up the mode word
  148. ;         from the header and OR-ing in the appropriate bitplane mode
  149. ;         bitfield. (This is not needed for text modes)
  150. ;      AX, CX, DX, SI can be trashed, PRESERVE DI!!!!
  151. ;
  152. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  153. ;--------------------------------------------------------------------------
  154. special_setup_table    label word
  155.     dw    offset  VGA_50row_mode_set
  156.     dw    offset  ET4000_HiColor_setup1
  157.     dw    offset  ET4000_HiColor_setup2
  158.     dw    offset  ET4000_HiColor_setup3
  159.  
  160. ;
  161. ; Routine to set up VGA 50 row mode
  162. ; interface is described above
  163. ;
  164. VGA_50row_mode_set    proc    near
  165.     mov    ax,03h            ; set 80x25 mode
  166.     int    10h
  167.     xor    bx,bx
  168.     mov    ax,1112h        ; load 8x8 font
  169.     int    10h
  170.     ret
  171. VGA_50row_mode_set       endp
  172.  
  173. ;
  174. ; Routine to set up ET4000 HiColor modes
  175. ; interface is described above
  176. ;
  177. ET4000_HiColor_setup1    proc    near
  178.     mov    al,BYTE PTR [di+6]    ; set up 256 colors w/ same WxH
  179.     xor    ah,ah
  180.     int    10h
  181.     mov    ax,10f0h
  182.     mov    bl,BYTE PTR [di+6]
  183.     int    10h                  ; set up HiColor w/ same size
  184.     cmp    ax,10h            ; success ?
  185.     je    ET4000_HiColor_Success1
  186.     mov    al,BYTE PTR [di+6]    ; go with the 256 color mode!
  187.     xor    ah,ah
  188.     int    10h
  189.     mov    BYTE PTR [di+6],0ffh;    ; disable this entry
  190.     mov    bx,GRD_8_PLANES
  191.     jmp    ET4000_HiColor_EndProc1
  192. ET4000_HiColor_Success1:
  193.     mov    bx,GRD_16_PLANES
  194. ET4000_HiColor_EndProc1:
  195.     or    bx,mode_W
  196.     ret
  197. ET4000_HiColor_setup1     endp
  198.  
  199.  
  200. ET4000_HiColor_setup2    proc    near
  201.     mov    al,BYTE PTR [di+6]    ; set up 256 colors w/ same WxH
  202.     xor    ah,ah
  203.     int    10h
  204.     mov    ax,10f0h
  205.     mov    bl,BYTE PTR [di+6]
  206.     int    10h                  ; set up HiColor w/ same size
  207.     cmp    ax,10h                    ; success ?
  208.         jne    back_256_2
  209.         mov    ax,10f2h
  210.         mov    bl,2
  211.         int    10h
  212.         cmp    ax,10h
  213.         jne    back_256_2
  214.         cmp    bl,2
  215.     je     ET4000_HiColor_Success2
  216. back_256_2:
  217.     mov    al,BYTE PTR [di+6]    ; go with the 256 color mode!
  218.     xor    ah,ah
  219.     int    10h
  220.     mov    BYTE PTR [di+6],0ffh;    ; disable this entry
  221.     mov    bx,GRD_8_PLANES
  222.     jmp    ET4000_HiColor_EndProc2
  223. ET4000_HiColor_Success2:
  224.     mov    bx,GRD_16X_PLANES
  225. ET4000_HiColor_EndProc2:
  226.     or    bx,mode_W
  227.     ret
  228. ET4000_HiColor_setup2     endp
  229.  
  230. ET4000_HiColor_setup3    proc    near
  231.     mov    al,BYTE PTR [di+6]    ; set up 256 colors w/ same WxH
  232.     xor    ah,ah
  233.     int    10h
  234.     mov    ax,10f0h
  235.     mov    bh,BYTE PTR [di+6]
  236.         mov    bl,0ffh
  237.     int    10h                    ; set up HiColor w/ same size
  238.     cmp    ax,10h               ; success ?
  239.     je     ET4000_HiColor_Success3
  240. back_256_3:
  241.     mov    al,BYTE PTR [di+6]    ; go with the 256 color mode!
  242.     xor    ah,ah
  243.     int    10h
  244.     mov    BYTE PTR [di+6],0ffh;    ; disable this entry
  245.     mov    bx,GRD_8_PLANES
  246.     jmp    ET4000_HiColor_EndProc3
  247. ET4000_HiColor_Success3:
  248.     mov    bx,GRD_24_PLANES
  249. ET4000_HiColor_EndProc3:
  250.     or    bx,mode_W
  251.     ret
  252. ET4000_HiColor_setup3     endp
  253.  
  254. ;--------------------------------------------------------------------------
  255. ; DRIVER INIT ROUTINE
  256. ;  called once after the driver is loaded
  257. ;  may do one or more of the followings:
  258. ;    - check for proper board type
  259. ;    - check amount of RAM on board, and:
  260. ;    -- update word in header to reflect correct amount
  261. ;    -- disable modes in the tables for which there is not enough RAM
  262. ;    - check for special equipment (HiColor DAC, etc...)
  263. ;
  264. ;  Entry: nothing
  265. ;
  266. ;  Exit:  AX=status:
  267. ;       non-zero: OK,
  268. ;       0: something went wrong (e.g. wrong adapter, etc..)
  269. ;      BX,CX,DX may be trashed
  270. ;
  271. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  272. ;--------------------------------------------------------------------------
  273. driver_init_routine    proc    far
  274.     mov    ax,10f1h        ; get DAC type
  275.     int    10h
  276.     cmp    ax,10h
  277.     jne    no_HiColor
  278. ;    cmp    bl,1
  279. ;     je    have_HiColor
  280.     jmp    have_HiColor
  281. no_HiColor:
  282.     mov    bx,offset ET4000_HiColor_Table
  283. kill_HiColor:
  284.     mov    BYTE PTR [bx+6],0ffh;    ; invalidate mode entry
  285.     add    bx,8
  286.     cmp    bx,offset ET4000_HiColor_EndTable
  287.     jne    kill_HiColor
  288. have_HiColor:
  289.     mov    ax,1
  290.     ret
  291. driver_init_routine    endp
  292.  
  293.  
  294. ;--------------------------------------------------------------------------
  295. ; MODE SET ROUTINE
  296. ;  sets up a text or graphics mode as close as possible to the one
  297. ;  reguested by the user with regard to number of colors and size.
  298. ;
  299. ;  Entry: AX=mode selection
  300. ;     0 = 80x25 text
  301. ;     1 = default text
  302. ;     2 = text CX cols by DX rows
  303. ;     3 = biggest text
  304. ;     4 = 320x200 graphics
  305. ;     5 = default graphics
  306. ;     6 = graphics CX width by DX height
  307. ;     7 = biggest non-interlaced graphics
  308. ;     8 = biggest graphics
  309. ;     9 = graphics BX colors, CX width by DX height
  310. ;
  311. ;  Exit: BX=driver mode flag
  312. ;     CX=width (in pixels or characters)
  313. ;     DX=height
  314. ;
  315. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  316. ;     YOU SHOULD NOT NEED TO CHANGE THIS ROUTINE AS IT IS PRETTY
  317. ;     MUCH TABLE DRIVEN
  318. ;--------------------------------------------------------------------------
  319. mode_set_routine    proc    far
  320.     push    ds
  321.     push    di
  322.     push    si
  323.     mov    si,cs
  324.     mov    ds,si
  325.     cmp    ax,9
  326.     jbe    DoIt
  327.     jmp    Exit
  328. DoIt:    add    ax,ax
  329.     mov    si,ax
  330.     jmp    WORD PTR mode_set_table[si]
  331. mode_set_table  label    word
  332.     dw    offset mode_0
  333.     dw    offset mode_1
  334.     dw    offset mode_2
  335.     dw    offset mode_3
  336.     dw    offset mode_4
  337.     dw    offset mode_5
  338.     dw    offset mode_6
  339.     dw    offset mode_7
  340.     dw    offset mode_8
  341.     dw    offset mode_9
  342. mode_0: mov    si,offset text_mode_table    ; 80x25 text
  343.     mov    bx,def_nc
  344.     mov    cx,80
  345.     mov    dx,25
  346.     jmp    Lookup
  347. mode_1: mov    si,offset text_mode_table    ; default text
  348.     mov    bx,def_nc
  349.     mov    cx,def_tw
  350.     mov    dx,def_th
  351.     jmp    Lookup
  352. mode_2: mov    si,offset text_mode_table    ; CX*DX text
  353.     mov    bx,def_nc
  354.     jmp    Lookup
  355. mode_3: mov    si,offset text_mode_table    ; biggest text
  356.     mov    bx,def_nc
  357.     mov    cx,Max_TW
  358.     mov    dx,Max_TH
  359.     jmp    Lookup
  360. mode_4: mov    si,offset graphics_mode_table    ; 320x200 graphics
  361.     mov    bx,def_nc
  362.     mov    cx,320
  363.     mov    dx,200
  364.     jmp    Lookup
  365. mode_5: mov    si,offset graphics_mode_table    ; default graphics
  366.     mov    bx,def_nc
  367.     mov    cx,def_gw
  368.     mov    dx,def_gh
  369.     jmp    Lookup
  370. mode_6: mov    si,offset graphics_mode_table    ; CX*DX graphics
  371.     mov    bx,def_nc
  372.     jmp    Lookup
  373. mode_7: mov    si,offset graphics_mode_table    ; biggest non-interlaced gr
  374.     mov    bx,def_nc
  375.     mov    cx,Max_GWn
  376.     mov    dx,Max_GHn
  377.     jmp    Lookup
  378. mode_8: mov    si,offset graphics_mode_table    ; biggest graphics
  379.     mov    bx,def_nc
  380.     mov    cx,Max_GW
  381.     mov    dx,Max_GH
  382.     jmp    Lookup
  383. mode_9: mov    si,offset graphics_mode_table    ; CX*DX graphics w/ BX colors
  384. ;
  385. ; At this point:
  386. ;   SI points to the table to search (text or graphics)
  387. ;   BX has colors
  388. ;   CX has width
  389. ;   DX has height
  390. ;
  391. Lookup: xor    ax,ax                ; last color number seen
  392. Find_C: cmp    [si+4],ax            ; last color number == this?
  393.     je    Same_C
  394.     jb    Prev_C                ; end of table -- use last color
  395.     cmp    BYTE PTR [si+6],0ffh        ; valid entry ?
  396.     je    Prev_C                ; not -- use last color
  397.     mov    ax,[si+4]            ; record color number
  398.     mov    di,si                ; start of entries w/ this color
  399.     cmp    ax,bx                ; enough colors ?
  400.     jae    Find_S
  401. Same_C: add    si,8
  402.     jmp    Find_C
  403. Prev_C: or    ax,ax                ; found any color at all?
  404.     je    Exit
  405. ;
  406. ; At this point:
  407. ;   DI points into the table to the first entry with the desired color
  408. ;      number (either it has enough colors or it is the highest color
  409. ;      number supported by the driver). Additionally, at least the
  410. ;      first (= smallest size) entry for this color is valid (has a
  411. ;      valid BIOS number).
  412. ;   AX has the color number adjusted for the driver
  413. ;   CX has width
  414. ;   DX has height
  415. ;
  416. Find_S: cmp    [di+4],ax            ; still the same color #?
  417.     jne    Prev_S
  418.     cmp    BYTE PTR [di+6],0ffh        ; valid entry ?
  419.     je    Prev_S
  420.     cmp    [di],cx
  421.     jb    Next_S
  422.     cmp    [di+2],dx
  423.     jae    GotIt
  424. Next_S: add    di,8
  425.     jmp    Find_S
  426. Prev_S: sub    di,8
  427. ;
  428. ; At this point:
  429. ;   DI points to the table entry we want to set up
  430. ;
  431. GotIt:  mov    ax,[di+6]            ; BIOS mode number
  432.     or    ah,ah                ; special ?
  433.     je    doBIOS
  434.     mov    al,ah
  435.     xor    ah,ah
  436.     dec    ax
  437.     add    ax,ax
  438.     mov    si,ax
  439.     call    WORD PTR special_setup_table[si]
  440.     jmp    RetVal
  441. doBIOS: 
  442.     mov    cx,ax
  443.     int    10h
  444.     mov    ax,0f00h
  445.     int    10h
  446.     cmp    al,cl
  447.     je    doBIOS_ok
  448.     xor    bx,bx
  449.     xor    dx,dx
  450.     xor     cx,cx
  451.     jmp    Exit
  452. doBIOS_ok:
  453.     mov    bx,GRD_1_PLANE
  454.     cmp    WORD PTR [di+4],2        ; 2 colors ?
  455.     je    doFLAG
  456.     mov    bx,GRD_4_PLANES
  457.     cmp    WORD PTR [di+4],16        ; 16 colors ?
  458.     je    doFLAG
  459.     mov    bx,GRD_8_PLANES
  460.     cmp    WORD PTR [di+4],256        ; 256 colors ?
  461.     je    doFLAG
  462.     mov    bx,GRD_16_PLANES
  463.     cmp    WORD PTR [di+4],32768        ; 32K colors ?
  464.     je    doFLAG
  465.     mov    bx,GRD_PLANE_MASK        ; something is wrong!!
  466. doFLAG: or    bx,mode_W
  467. RetVal: mov    cx,[di]
  468.     mov    dx,[di+2]
  469. Exit:    pop    si
  470.     pop    di
  471.     pop    ds
  472.     ret
  473. mode_set_routine         endp
  474.  
  475.  
  476. ;--------------------------------------------------------------------------
  477. ; PAGING ROUTINE
  478. ;
  479. ;  Entry: AH=read page
  480. ;      AL=write page
  481. ;
  482. ;  Exit: VGA configured.
  483. ;     AX,BX,CX,DX,SI,DI may be trashed
  484. ;
  485. ;  NOTE: This runs in protected mode!  Don't mess with the segment registers!
  486. ;     This code must be relocatable and may not reference any data!
  487. ;--------------------------------------------------------------------------
  488.     assume  ds:nothing, es:nothing
  489.  
  490. paging_routine  proc    far
  491.     and    al,0fh
  492.     mov    cl,4
  493.     shl    ah,cl
  494.     and    ah,0f0h
  495.     or    al,ah
  496.     mov    dx,03cdh
  497.     out    dx,al
  498.     ret
  499. paging_routine  endp
  500.  
  501.  
  502. cseg    ends
  503.     end
  504.  
  505.